<template>
  <div style="">
    <Header :left="true" leftText="返回" title="品管主任审核"> </Header>
    <div class="textScroll">
      <!-- 文字信息 -->
      <van-row style="margin-top: 10px">
        <van-col>
          <van-image width="40" height="30" style="margin-left: -10px" src="assets/block.png" />
        </van-col>
        <van-col class="message" style="margin-top: 5px">问题产品处置申请信息</van-col>
      </van-row>
      <div class="divMessage">
        <van-form :style="autoHeight">
          <van-row style="margin-left: 10px; margin-top: 10px">
            <van-col span="5"><b>工厂:</b></van-col>
            <van-col span="19">{{ item.FactoryID }}</van-col>
          </van-row>
          <van-row style="margin-left: 10px; margin-top: 10px">
            <van-col span="5"><b>生产线编码:</b></van-col>
            <van-col span="19">{{ item.PLineID }}</van-col>
          </van-row>
          <van-row style="margin-left: 10px; margin-top: 10px">
            <van-col span="5"><b>订单号码:</b></van-col>
            <van-col span="19">{{ item.POrderID }}</van-col>
          </van-row>
          <van-row style="margin-left: 10px; margin-top: 10px">
            <van-col span="5"><b>产品名称:</b></van-col>
            <van-col span="19">{{ item.MaterialName }}</van-col>
          </van-row>
          <van-row style="margin-left: 10px; margin-top: 10px">
            <van-col span="5"><b>产品代码:</b></van-col>
            <van-col span="19">{{ item.MaterialID }}</van-col>
          </van-row>
          <van-row style="margin-left: 10px; margin-top: 10px">
            <van-col span="5"><b>生产日期:</b></van-col>
            <van-col span="19">{{ item.ProductionDate }}</van-col>
          </van-row>
          <!-- <van-row style="margin-left: 10px; margin-top: 10px">
            <van-col span="5"><b>生产班次:</b></van-col>
            <van-col span="19">{{ showShiftIDName(item.PShiftID) }}</van-col>
          </van-row>
          <van-row style="margin-left: 10px; margin-top: 10px">
            <van-col span="5"><b>生产班组:</b></van-col>
            <van-col span="19">{{ showTeamIDName(item.TeamID) }}</van-col>
          </van-row> -->

          <van-row style="margin-left: 10px; margin-top: 10px">
            <van-col span="5"><b>问题批次号:</b></van-col>
            <van-col span="19">{{ item.BatchID }}</van-col>
          </van-row>
          <van-row style="margin-left: 10px; margin-top: 10px">
            <van-col span="5"><b>待处理数量:</b></van-col>
            <van-col span="19">{{ item.DeFectAmount }} &nbsp; {{ item.MUnitID }}</van-col>
          </van-row>
          <van-row style="margin-left: 10px; margin-top: 10px">
            <van-col span="5"><b>缺陷类型:</b></van-col>

            <van-col span="19">

              <van-field readonly style="font-weight: bold;border:1px solid #ccc!important;width: 95%;margin: 0 auto;"
                v-model="text" class="formstyle" rows="4" autosize label="" type="textarea" maxlength="150" placeholder=""
                show-word-limit />
            </van-col>
          </van-row>
          <van-row style="margin-left: 10px; margin-top: 10px">
            <van-col span="5"><b>缺陷描述:</b></van-col>
            <van-col span="19">{{ item.DefectMemo }}</van-col>
          </van-row>
          <van-row style="margin-left: 10px; margin-top: 10px">
            <van-col span="5"><b>发起时间:</b> </van-col>
            <van-col span="19">
              {{ item.Creator }} &nbsp; {{ item.CreateDatetime }}
            </van-col>
          </van-row>
          <!-- <van-row style="margin-left: 10px; margin-top: 10px">
            <van-col span="5"><b>建议处置方式:</b></van-col>
            <van-col span="19">{{ showDealType(item.AdviceDealType) }}</van-col>
          </van-row>
          <van-row style="margin-left: 10px; margin-top: 10px">
            <van-col span="5"><b>建议处置意见:</b></van-col>
            <van-col span="19">{{ item.AdviceMemo }}</van-col>
          </van-row> -->
        </van-form>

        <van-row gutter="20">
          <van-col span="12">
            <div style="margin: 16px">
              <van-button color="#008792" round block type="info" @click="getRecord(form.AppearanceCheckRecord1)"
                style="">查看外观检验不合格记录</van-button>
            </div>
          </van-col>
          <van-col span="12">
            <div style="margin: 16px">
              <van-button color="#33a3dc" round block type="info" @click="checkSYS">查看实验室检验不合格项</van-button>
            </div>
          </van-col>
        </van-row>

        <van-row gutter="20">
          <van-col span="12">
            <div style="margin: 16px">
              <van-button color="#1AB394" round block type="info" @click="openQA">打开质量辅助决策界面</van-button>
            </div>
          </van-col>
          <van-col span="12">
            <div style="margin: 16px">
              <van-button color="#005831" round block type="info" @click="CheckTM">查看实验室复测记录</van-button>
            </div>
          </van-col>
        </van-row>
      </div>

      <NoticeBar color="#1989fa" background="#ecf9ff" style="margin-top: 5px; font-size: 15px; font-weight: bold"
        left-icon="description">品管领班审核意见</NoticeBar>
      <!-- <van-row style="margin-left: 10px; margin-top: 10px">
        <van-col span="5"><b>是否同意:</b></van-col>
        <van-col span="19">
          <span v-if="item.QCLeaderAgree == '1' ? true : false">同意处置意见</span>
          <span v-else>不同意处置意见</span>
        </van-col>
      </van-row> -->
      <van-row style="margin-left: 10px; margin-top: 10px">
        <van-col span="5"><b>处理方式:</b></van-col>
        <van-col span="19">{{
          showDealType(item.QCLeaderAdviceDealType)
        }}</van-col>
      </van-row>
      <van-row style="margin-left: 10px; margin-top: 10px">
        <van-col span="5"><b>处置建议:</b></van-col>
        <van-col span="19">{{ item.QCLeaderMemo }}</van-col>
      </van-row>
      <NoticeBar color="#1989fa" background="#ecf9ff" style="margin-top: 5px; font-size: 15px; font-weight: bold"
        left-icon="description">品管主任审核意见</NoticeBar>
      <van-field name="是否同意" class="formstyle" label="判断意见" required>
        <template #input>
          <van-radio-group v-model="QCMangerAgreeValue" direction="horizontal" @change="changeAgreeValue">
            <van-radio name="1" checked-color="#138087">同意放行</van-radio>
            <van-radio name="0" checked-color="#138087">不同意放行</van-radio>
          </van-radio-group>
        </template>
      </van-field>
      <!-- 通过 -->
      <van-field required readonly v-show="isAllow" class="formstyle" name="picker" :value="valuepDealTypeName"
        label="处理方式" placeholder="点击选择处理方式" />
      <!-- 不同意 -->
      <van-field v-show="notAllow" required readonly class="formstyle" name="picker" :value="valuepDealTypeName"
        label="处理方式" placeholder="选择品管主任处理方式" @click="showPickerDealType = true" />
      <van-popup v-model="showPickerDealType" position="bottom">
        <van-picker show-toolbar :columns="columnsDealType" @confirm="onConfirmDealType"
          @cancel="showPickerDealType = false">
          <template #option="option">
            <div style="display: flex; flex-direction: column; align-items: center">
              <div>{{ option.DealTypeName }}</div>
            </div>
          </template>
        </van-picker>
      </van-popup>
      <van-field class="formstyle" v-model="form.TeamLeaderMemo" required name="处置建议" label="处置建议"
        placeholder="输入品管主任处置建议" rows="2" autosize type="textarea" maxlength="100" show-word-limit />

      <van-field v-show="showCT02" required readonly class="formstyle" name="picker" :value="EmployeeName" label="生产现场主管"
        placeholder="点击选择生产现场主管" @click="showPickerEmployee = true" />
      <van-popup v-model="showPickerEmployee" position="bottom">
        <van-picker show-toolbar :columns="columnsEmployeeND" @confirm="onConfirmEmployee"
          @cancel="showPickerEmployee = false">
          <template #option="option">
            <div style="display: flex; flex-direction: column; align-items: center">
              <div>{{ option.EmployeeName }}</div>
            </div>
          </template>
          <template #title>
            <van-field v-model="searchKey1" placeholder="请输入搜索内容" clearable />
          </template>
        </van-picker>
      </van-popup>

      <van-field v-show="showCT03" required readonly class="formstyle" name="picker" :value="EmployeeName" label="生产部门负责人"
        placeholder="点击选择生产部门负责人" @click="showPickerEmployee = true" />
      <van-popup v-model="showPickerEmployee" position="bottom">
        <van-picker show-toolbar :columns="columnsEmployeeND" @confirm="onConfirmEmployee"
          @cancel="showPickerEmployee = false">
          <template #option="option">
            <div style="display: flex; flex-direction: column; align-items: center">
              <div>{{ option.EmployeeName }}</div>
            </div>
          </template>
          <template #title>
            <van-field v-model="searchKey1" placeholder="请输入搜索内容" clearable />
          </template>
        </van-picker>
      </van-popup>
      <van-field required readonly class="formstyle" label="审核时间" :value="nowDate" />
      <div style="margin: 16px">
        <van-button color="#138087" round block type="info" native-type="submit" @click="submitsure">保存</van-button>
      </div>
    </div>
  </div>
</template>

<script>
import {
  Col,
  Row,
  Form,
  Cell,
  Icon,
  Field,
  NumberKeyboard,
  Image as VanImage,
  Picker,
  popup,
  SubmitBar,
  Button,
  Loading,
  Overlay,
  Dialog,
  Toast,
  NoticeBar,
  Tag,
  DatetimePicker,
  ImagePreview,
  CellGroup,
  Uploader,
  Cascader,
  Calendar,
  RadioGroup,
  Radio,
  Divider,
  Stepper,
  AddressList,
  Checkbox,
  CheckboxGroup,
} from "vant";

import "vue-easytable/libs/themes-base/index.css";
import { VTable } from "vue-easytable";
import { _httpClient } from "@/libs/apisie";
import { getToken, getBaseApiFrefix } from "@/libs/auth";
import Header from "@/components/header.vue";
import { storage } from "@/libs/utils";

Vue.use(Form);
Vue.use(Field);
Vue.use(Overlay);
Vue.use(Loading);
Vue.use(Picker);
Vue.use(popup);
Vue.use(SubmitBar);
Vue.use(VanImage);
Vue.use(DatetimePicker);
Vue.use(Cascader);
Vue.use(Calendar);
Vue.use(Cell);
Vue.use(RadioGroup);
Vue.use(Radio);
Vue.use(Divider);
Vue.use(Stepper);
Vue.use(Button);
Vue.use(AddressList);
Vue.use(Checkbox);
Vue.use(CheckboxGroup);
Vue.use(Col);
Vue.use(Row);

export default {
  name: "ckCheck02Item",
  components: {
    Form,
    Row,
    Col,
    Button,
    Header,
    Form,
    Cell,
    Icon,
    Field,
    NumberKeyboard,
    Dialog,
    Toast,
    NoticeBar,
    Row,
    Tag,
    popup,
    DatetimePicker,
    ImagePreview,
    CellGroup,
    Uploader,
    Col,
    Calendar,
    Cascader,
    Picker,
    RadioGroup,
    Radio,
    Divider,
    Stepper,
    VTable,
    AddressList,
    Checkbox,
    CheckboxGroup,
  },
  data() {
    return {
      searchKey1: "",
      columnsEmployeeND: [],
      isallow: true,
      minDate: new Date(2022, 12, 1),
      nowDate: null,
      form: {
        EmployeeID: "",
        TeamLeaderAgree: "",
        QCLeaderAdviceDealType: "",
        TeamLeaderMemo: "",
        TeamLeaderAdviceDealType: "",
      },
      user: [],
      plineID: "",
      text: "",
      time: "",
      FactoryID: "",
      valuepShiftName: "",
      CheckTypeName: "",
      QProblemName: "",
      valueteamid: "",
      BeginTime: "",
      WorkPlanDatetimeFrom: "",
      columnsteamId: [],
      showPickerteamid: false,
      showPickerpShiftID: false,
      showPickerDealType: false,
      valueemployid: "",
      columnsshift: [],
      columnsType: [],
      columnsDealType: [],
      columnsQProblem: [],
      showPickerType: false,
      showPickerQProblem: false,
      item: {},
      valuepDealTypeName: "",
      QCMangerAgreeValue: "",
      showPickerEmployee: false,
      columnsEmployee: [],
      columnsEmployee2: [],
      columnsEmployee1: [],
      EmployeeName: "",
      showSC: false,
      showZL: false,
      showCT02: false,
      showCT03: false,
      flag: false,
    };
  },
  destroyed() {
    clearInterval(this.nowtimer);
    this.nowDate = null;
  },
  created: function () {
    this.user = JSON.parse(storage.get("user"));
    this.user.userId = this.user.userName;
    this.item = api.pageParam.item;
    this.text = this.item.QProblemID + this.item.ManageReasonID + this.item.FunctionProblemID
    // alert(JSON.stringify(this.item))
    this.columnsteamId = api.pageParam.columnsteamId;
    this.columnsshift = api.pageParam.columnsshift;
    this.getQualityProblems();
    //获取建议处置方式
    this.getDealType();
    //获取员工列表
    //this.getEmployeeID();
    this.getEmployeeID1();
    this.getUsername(this.item.Creator)
    //this.form.TeamLeaderAdviceDealType == "DT04";
  },
  mounted() {

  },
  watch: {  //实时监听搜索输入内容
    'searchKey': {
      handler(newVal) {
        let key = String(newVal);
        //alert(key);
        key = key.replace(/\s*/g, "");
        const reg = new RegExp(key, "ig");
        /* 进行筛选，将筛选后的数据放入新的数组中，‘name’键可根据需要搜索的key进行调整 */
        this.searchColumns = this.columnspline.filter(item => item.plineName.match(reg) != null);
        //alert(this.searchColumns);
      },
      deep: true,
      immediate: true,
    },

    'searchKey1': {
      handler(newVal) {
        let key = String(newVal);
        //alert(key);
        key = key.replace(/\s*/g, "");
        const reg = new RegExp(key, "ig");
        /* 进行筛选，将筛选后的数据放入新的数组中，‘name’键可根据需要搜索的key进行调整 */
        this.columnsEmployeeND = this.columnsEmployee.filter(item => item.EmployeeName.match(reg) != null);
        //alert(this.searchColumns);
      },
      deep: true,
      immediate: true,
    },

    'searchKey2': {
      handler(newVal) {
        let key = String(newVal);
        //alert(key);
        key = key.replace(/\s*/g, "");
        const reg = new RegExp(key, "ig");
        /* 进行筛选，将筛选后的数据放入新的数组中，‘name’键可根据需要搜索的key进行调整 */
        this.statColumn2 = this.statColumn.filter(item => item.POrderIDAndMaterialName.match(reg) != null);
        //alert(this.searchColumns);
      },
      deep: true,
      immediate: true,
    },
  },
  methods: {
    getRecord(id) {


      api.openWin({
        name: 'qCcheckReview',
        url: './quality-qCcheckReview.html',
        pageParam: {
          id: id
        }
      });

    },
    async CheckTM() {

      let id = this.item.LaboratoryCheckRecord
      let CheckItem = this.item.CheckItem;
      let CheckBatch = this.item.CheckBatch;

      if (CheckBatch == "全项检验") {
        CheckBatch = "问题产品复核检验-全项"
      }
      else {
        CheckBatch = "问题产品复核检验-过程"
      }

      if (id == "" || id == null || id == undefined) {
        Toast.clear()
        Toast.fail("当前没有维护实验室复测记录，无法获取复测记录！")
        return
      }

      api.openWin({
        name: 'viewlaboratorytest1',
        url: './equipmentsj-viewlaboratorytest1.html',
        pageParam: {
          id: this.item.LaboratoryCheckRecord,
          CheckBatch: CheckBatch,
          CheckItem: this.item.CheckItem
        }
      });
    },
    async checkSYS() {

      let id = this.item.LaboratoryCheckRecord;
      let CheckItem = this.item.CheckItem;
      let CheckBatch = this.item.CheckBatch;

      if (id == "" || id == null || id == undefined) {
        Toast.clear()
        Toast.fail("当前没有维护实验室复测记录，无法获取复测记录！")
        return
      }

      api.openWin({
        name: 'viewlaboratorytest',
        url: './equipmentsj-viewlaboratorytest.html',
        pageParam: {
          id: this.item.LaboratoryCheckRecord,
          CheckBatch: this.item.CheckBatch,
          CheckItem: this.item.CheckItem
        }
      });
    },
    async getUsername(id) {


      try {

        let res4 = await _httpClient.get(
          _httpClient.getApiPrefix() + "/Employee/GetList?EmployeeID=" + id)
        // alert(JSON.stringify(res4))
        if (res4.Data.length > 0) {
          // alert("-xxx-")
          this.item.Creator = res4.Data[0].EmployeeName
          return
        }
      } catch (e) {
        alert(JSOn.stringify(e))
      }
      this.item.Creator = id
    },
    openQA() {
      let _this = this
      // alert(_this.form.POrderID)
      api.openWin({
        name: 'qAssistance',
        url: './qAssistance-qualityAssistance.html',
        pageParam: {
          POrderID: _this.item.POrderID,
          PlineID: _this.item.PLineID
        }
      });


    },
    getTime() {
      var date = new Date();
      date.setMinutes(date.getMinutes() - date.getTimezoneOffset());
      this.nowDate = date.toJSON().substr(0, 19).replace("T", " ");
    },
    showTeamIDName(teamID) {
      var teamName = teamID;
      this.columnsteamId.forEach((item) => {
        if (item.teamID === teamID) {
          teamName = item.teamName;
        }
      });
      return teamName;
    },
    showShiftIDName(pShiftID) {
      var pShiftName;
      this.columnsshift.forEach((item) => {
        if (item.pShiftID === pShiftID) {
          pShiftName = item.pShiftName;
        }
      });
      return pShiftName;
    },
    onConfirmDealType(value, index) {
      this.showCT02 = false;
      this.valuepDealTypeName = this.columnsDealType[index].DealTypeName;
      this.form.TeamLeaderAdviceDealType =
        this.columnsDealType[index].DealTypeID;
      if (this.form.TeamLeaderAdviceDealType == "DT04") {
        this.showCT03 = false;
        this.showCT02 = false;
        this.flag = false;
      } else {
        this.showCT03 = false;
        this.showCT02 = true;
        this.flag = true;
      }
      this.showPickerDealType = false;
    },
    showQProblemID(QProblemID) {
      var QProblemName;
      this.columnsQProblem.forEach((item) => {
        if (item.QProblemID === QProblemID) {
          QProblemName = item.QProblemName;
        }
      });
      return QProblemName;
    },
    showDealType(type) {
      var DealTypeName;
      this.columnsDealType.forEach((item) => {
        if (item.DealTypeID === type) {
          DealTypeName = item.DealTypeName;
        }
      });
      return DealTypeName;
    },
    changeAgreeValue() {
      this.getTime();
      this.showCT02 = false;
      //如果同意
      // alert(this.QCMangerAgreeValue)
      if (this.QCMangerAgreeValue == "1") {

        this.item.TeamLeaderAdviceDealType = "DT04";
        if (this.item.TeamLeaderAdviceDealType == "DT04") {
          this.showCT02 = false;
        } else {
          this.showCT02 = true;
        }

        // alert(this.showCT02)
        this.isAllow = true;
        this.notAllow = false;
        this.form.TeamLeaderAgree = true;
        this.valuepDealTypeName = "质量合格不做处理";
        this.form.TeamLeaderMemo =
          this.nowDate +
          ":" +
          "品管主任:" +
          this.user.employeeName +
          "已经做出判断!";
      } else {
        this.isAllow = false;
        this.notAllow = true;
        //若不同意
        this.form.TeamLeaderAgree = false;
        this.valuepDealTypeName = "";
        this.form.TeamLeaderMemo =
          this.nowDate +
          ":" +
          "品管主任:" +
          this.user.employeeName +
          "已经做出判断!";
      }
    },
    //获取员工列表
    async getEmployeeID() {
      let _this = this;
      //_this.columnsEmployee=[];
      try {
        let res = await _httpClient.get(
          _httpClient.getApiPrefix() + "/Employee/GetList?PositionID=GW21"
        );
        if (res.HttpCode === "200") {
          let temp = res.Data.map((item) => ({
            EmployeeID: item.EmployeeID,
            EmployeeName: item.EmployeeName,
          }));
          temp.forEach((item) => {
            _this.columnsEmployee.push(item);
            _this.columnsEmployeeND.push(item);
          });
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    //获取员工列表
    async getEmployeeID1() {
      let _this = this;
      try {
        let res = await _httpClient.get(
          _httpClient.getApiPrefix() + "/Employee/GetList?PositionID=GW21"
        );
        if (res.HttpCode === "200") {
          let temp = res.Data.map((item) => ({
            EmployeeID: item.EmployeeID,
            EmployeeName: item.EmployeeName,
          }));
          temp.forEach((item) => {
            _this.columnsEmployee.push(item);
            _this.columnsEmployeeND.push(item);
          });
        }


        res = await _httpClient.get(
          _httpClient.getApiPrefix() + "/Employee/GetList?PositionID=GW35"
        );
        if (res.HttpCode === "200") {
          let temp = res.Data.map((item) => ({
            EmployeeID: item.EmployeeID,
            EmployeeName: item.EmployeeName,
          }));
          temp.forEach((item) => {
            _this.columnsEmployee.push(item);
            _this.columnsEmployeeND.push(item);
          });
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    onConfirmEmployee(value, index) {
      this.form.EmployeeID = this.columnsEmployeeND[index].EmployeeID;
      this.EmployeeName = this.columnsEmployeeND[index].EmployeeName;
      this.showPickerEmployee = false;
    },
    //获取缺陷原因
    async getQualityProblems() {
      let _this = this;
      try {
        let res = await _httpClient.get(
          _httpClient.getApiPrefix() + "/QualityProblems/GetList"
        );
        if (res.HttpCode === "200") {
          let temp = res.Data.map((item) => ({
            QProblemID: item.QProblemID,
            QProblemName: item.QProblemName,
          }));
          temp.forEach((item) => {
            _this.columnsQProblem.push(item);
          });
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    async sendmessage() {
      let _this = this;

      let eventDescription = "";
      let eventDatetime = _this.getNowTime();
      let eventTypeID = "N3";
      let eventID = "";
      let messageContent = "";
      let msgContentTypeID = "";
      let pLineID = _this.item.PLineID;
      let machineID = _this.item.PLineID;
      let pShiftID = "";
      let teamID = "";
      let pOrderID = _this.item.POrderID;
      let productionBarcode = "";
      let materialBarcode = "";
      let relatedEmployee = "";
      let messageStatus = "";
      let processBatchID = "";
      let beginDatetime = _this.getNowTime();
      let sendFinished = false;
      let closed = false;

      msgContentTypeID = "EV003";
      eventID = "DF001";
      eventDescription = "问题产品处置申请单于:" + _this.item.CreateDatetime + "已经被品管主任进行审核，请生产现场主管进行处理！";
      messageContent = "生产订单" + _this.item.POrderID + "在生产线:" + _this.item.PLineID + "上生产时发生质量问题，质量原因是:" + _this.item.DefectMemo + " 请生产现场主管进行进行审核！";

      let bodysss = {
        eventDescription: eventDescription,
        eventDatetime: eventDatetime,
        eventTypeID: eventTypeID,
        eventID: eventID,
        messageContent: messageContent,
        msgContentTypeID: msgContentTypeID,
        factoryID: "TC00",
        pLineID: pLineID,
        machineID: machineID,
        pShiftID: pShiftID,
        teamID: teamID,
        pOrderID: pOrderID,
        productionBarcode: productionBarcode,
        materialBarcode: materialBarcode,
        relatedEmployee: relatedEmployee,
        messageStatus: messageStatus,
        processBatchID: processBatchID,
        beginDatetime: beginDatetime,
        sendFinished: sendFinished,
        closed: closed
      };
      try {
        let res = await _httpClient.post(
          _httpClient.getApiPrefix() + "/RealtimeEventMessage/SaveEntity",
          {
            body: bodysss,
          }
        );
        //alert(JSON.stringify(res));
        if (res.Message == null) {
          Toast.clear();
          Toast.success("发送成功");
          api.sendEvent({
            name: "reloadCK02",
          });
          setTimeout(function () {
            _this.$ac.closeWin();
          }, 2000);

        } else {
          Toast.clear();
          Toast.fail("发送失败");
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    async sendmessage2() {
      let _this = this;

      let eventDescription = "";
      let eventDatetime = _this.getNowTime();
      let eventTypeID = "N3";
      let eventID = "";
      let messageContent = "";
      let msgContentTypeID = "";
      let pLineID = _this.item.PLineID;
      let machineID = _this.item.PLineID;
      let pShiftID = "";
      let teamID = "";
      let pOrderID = _this.item.POrderID;
      let productionBarcode = "";
      let materialBarcode = "";
      let relatedEmployee = "";
      let messageStatus = "";
      let processBatchID = "";
      let beginDatetime = _this.getNowTime();
      let sendFinished = false;
      let closed = false;

      msgContentTypeID = "EV007";
      eventID = "DF001";

      eventDescription = "问题产品处置申请单于:" + _this.item.CreateDatetime + "品管主任判定合格，请相关岗位知悉！";
      messageContent = "生产订单" + _this.item.POrderID + "在生产线:" + _this.item.PLineID + "，问题产品处置申请单于:" + _this.item.CreateDatetime + "品管主任判定合格，请相关岗位知悉！";
      let bodysss = {
        eventDescription: eventDescription,
        eventDatetime: eventDatetime,
        eventTypeID: eventTypeID,
        eventID: eventID,
        messageContent: messageContent,
        msgContentTypeID: msgContentTypeID,
        factoryID: "TC00",
        pLineID: pLineID,
        machineID: machineID,
        pShiftID: pShiftID,
        teamID: teamID,
        pOrderID: pOrderID,
        productionBarcode: productionBarcode,
        materialBarcode: materialBarcode,
        relatedEmployee: relatedEmployee,
        messageStatus: messageStatus,
        processBatchID: processBatchID,
        beginDatetime: beginDatetime,
        sendFinished: sendFinished,
        closed: closed
      };
      try {
        let res = await _httpClient.post(
          _httpClient.getApiPrefix() + "/RealtimeEventMessage/SaveEntity",
          {
            body: bodysss,
          }
        );
        //alert(JSON.stringify(res));
        if (res.Message == null) {
          Toast.clear();
          Toast.success("发送成功");
          api.sendEvent({
            name: "reloadCK02",
          });
          setTimeout(function () {
            _this.$ac.closeWin();
          }, 2000);

        } else {
          Toast.clear();
          Toast.fail("发送失败");
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    getNowTime() {
      let dateTime
      let yy = new Date().getFullYear()
      let mm = new Date().getMonth() + 1
      let dd = new Date().getDate()
      let hh = new Date().getHours()
      let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes()
        :
        new Date().getMinutes()
      let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds()
        :
        new Date().getSeconds()
      dateTime = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss
      return dateTime
    },
    //获取建议处置方式
    async getDealType() {
      let _this = this;
      try {
        let res = await _httpClient.get(
          _httpClient.getApiPrefix() + "/QualityDealType/GetList"
        );
        if (res.HttpCode === "200") {
          let temp = res.Data.map((item) => ({
            DealTypeID: item.DealTypeID,
            DealTypeName: item.DealTypeName,
          }));
          temp.forEach((item) => {
            if (item.DealTypeID != "DT03" && item.DealTypeID != "DT04") {
              _this.columnsDealType.push(item);
            }
          });
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    //确认提交表单
    async submitsure() {
      let _this = this;
      // if (_this.QCMangerAgreeValue == "1") {
      //   if (_this.EmployeeName == "") {
      //     alert("请选择生产现场主管");
      //     return;
      //   }
      // } else 
      if (_this.QCMangerAgreeValue == "0") {
        if (_this.EmployeeName == "") {
          alert("请选择生产现场主管");
          return;
        }
        if (_this.valuepDealTypeName == "") {
          alert("请选择处置方式");
          return;
        }
      }
      var sendData = {};
      sendData.TeamLeaderAgree = this.form.TeamLeaderAgree;
      sendData.TeamLeaderMemo = this.form.TeamLeaderMemo;
      sendData.TeamLeaderCheckDatetime = this.nowDate;
      sendData.TeamLeaderChecked = true;
      //sendData.TeamLeaderAdviceDealType = this.form.TeamLeaderAdviceDealType;
      sendData.id = this.item.Id;
      //alert(_this.QCMangerAgreeValue);
      if (_this.QCMangerAgreeValue == "1") {
        if (_this.item.TeamLeaderAdviceDealType == "DT04") {

          //同意放行
          sendData.FromTeamLeader = _this.flag;
          // sendData.FixedDatetime = new Date();
          sendData.OnSiteLeaderUserID = _this.form.EmployeeID;
          //最终解决方式
          sendData.FixedDealType = _this.item.TeamLeaderAdviceDealType;
          sendData.TeamLeaderAdviceDealType = _this.item.TeamLeaderAdviceDealType;
        } else {
          //其他处理方式
          sendData.PrdMangerUserID = _this.form.EmployeeID;
          sendData.FromTeamLeader = false;
          sendData.OnSiteLeaderUserID = _this.form.EmployeeID;
          sendData.TeamLeaderAgree = false;
          sendData.TeamLeaderAdviceDealType = _this.item.QCLeaderAdviceDealType;
        }
      } else {

        if (_this.form.TeamLeaderAdviceDealType == "DT04") {

          //如果是放行
          sendData.PrdMangerUserID = _this.form.EmployeeID;
          sendData.FromTeamLeader = false;
          sendData.TeamLeaderAgree = false;
          sendData.OnSiteLeaderUserID = _this.form.EmployeeID;
          sendData.FixedDealType = "DT04";
          sendData.TeamLeaderAdviceDealType =
            _this.form.TeamLeaderAdviceDealType;
        } else {
          //如果不是放行
          sendData.PrdMangerUserID = _this.form.EmployeeID;
          sendData.FromTeamLeader = false;
          sendData.TeamLeaderAgree = false;
          sendData.OnSiteLeaderUserID = _this.form.EmployeeID;
          sendData.TeamLeaderAdviceDealType =
            _this.form.TeamLeaderAdviceDealType;
        }
      }
      Toast.loading({
        mask: true,
        forbidClick: true,
        duration: 0,
        message: "请稍等...",
      });
      // alert(JSON.stringify(sendData))
      try {
        let res = await _httpClient.post(
          _httpClient.getApiPrefix() + "/QualityDefectReview/SaveEntity",
          {
            body: sendData,
          }
        );
        if (res.Message != null) {
          //message不为空,有报错信息，打卡失败 暂时这样判断
          Toast.clear();
          Toast.fail("保存失败,请核对信息！");
        } else {
          //打卡成功
          Toast.clear();
          Toast.success("保存成功！");
          // alert(this.QCMangerAgreeValue)
          if (this.QCMangerAgreeValue == "1") {

            _this.sendmessage2();
          } else {
            _this.sendmessage();
          }

          // api.sendEvent({
          //   name: "reloadCK02",
          // });
          // setTimeout(function () {
          //   _this.$ac.closeWin();
          // }, 2000);
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
  },
};
</script>

<style>
body {
  background-color: white;
}

.table-title-class {
  background-color: #304156;
  color: #fff;
}

.wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.buttongroup {
  float: right;
  margin-right: 10px;
  margin-top: 10px;
  margin-bottom: 20px;
}

.container.dwo {
  display: flex;
  justify-content: center;
  align-items: center;
}

.buttonLeft {
  position: fixed;
  bottom: 8px;
  float: left;
  width: 49%;
}

.formstyle {
  margin-top: 8px;
  font-size: 15px;
  font-weight: bold;
  display: flex;
  align-items: center;
}

.radioteam {
  display: flex;
  align-items: center;
  padding-left: 13px;
  margin-top: 10px;
  margin-left: 34px;
  margin-bottom: 10px;
}

.buttonRight {
  position: fixed;
  bottom: 8px;
  float: right;
  left: 51%;
  width: 49%;
  background-color: #f22028;
  border-color: #f22028;
}

.textScroll {
  display: inline-block;
  position: fixed;
  top: 5rem;
  bottom: 0rem;
  overflow: scroll;
  right: 0;
  width: 100%;
  z-index: 1;
}

.message {
  font-size: 15px;
  margin-top: 5px;
  margin-left: -10px;
  font-weight: bold;
}

.mg5 {
  margin-right: 5px;
}

.tag_margin {
  margin: 2px 5px;
}

.card_under {
  height: 100%;
  width: 100%;
  margin: auto;
  background: #ffffff;
  border-radius: 25px;
  box-shadow: 0 0px 0px rgba(0, 0, 0, 0.3);
}

.card_icon {
  text-align: center;
  /* position: absolute; */
  height: 8rem;
  width: 80%;
  margin: 12% 10%;
  background: rgba(35, 180, 237, 1);
  border-radius: 25px;
  box-shadow: 0 10px 50px rgba(0, 0, 0, 0.3);
}

.text {
  font-size: 18px;
  color: #4e4a67;
  margin: 8px auto auto 20px;
  line-height: 1.5rem;
  text-align: justify;
  font-weight: 600;
}

.text_small {
  font-size: 16px;
  color: red;
  margin: 8px auto auto 20px;
  line-height: 1.5rem;
  text-align: justify;
  font-weight: 700;
}

.text_scan {
  font-size: 16px;
  color: #4e4a67;
  margin: auto auto auto 20px;
  line-height: 1.5em;
  text-align: justify;
}

.divStyle {
  margin-left: 3px;
  margin-right: 3px;
}

.divMessage {
  margin-top: 0px;
  border: solid #dcdcdc;
  margin-left: 5px;
  margin-right: 15px;
  border-top-width: 4px;
  border-left-width: 4px;
  border-right-width: 1px;
  border-bottom-width: 1px;
}
</style>
